package com.zmn.oms.services.impl.ins;

import com.zmn.oms.model.entity.ins.InsOrder;
import com.zmn.oms.persistence.interfaces.ins.InsOrderDao;
import com.zmn.oms.services.interfaces.ins.InsOrderService;
import com.zmn.oms.services.interfaces.orderencrypt.InsOrderEncryptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类描述：保险单
 *
 * @author liuying
 * @date 2019/01/23 10:48
 */
@Service
public class InsOrderServiceImpl implements InsOrderService {

    @Resource
    private InsOrderDao insOrderDao;
    @Autowired
    private InsOrderEncryptService insOrderEncryptService;

    @Override
    public InsOrder findInsOrderByOrderId(Long orderId) {
        InsOrder insOrder = insOrderDao.findInsOrderByOrderId(orderId);
        return insOrderEncryptService.decryptInsOrder(insOrder);
    }

    @Override
    public List<InsOrder> listInsOrderByOrderIds(List<Long> orderIds) {
        List<InsOrder> insOrders = insOrderDao.listInsOrderByOrderIds(orderIds);
        return insOrderEncryptService.batchDecryptInsOrder(insOrders);
    }

    @Override
    public InsOrder findInsOrderByKey(Long insId) {
        InsOrder insOrder = insOrderDao.findInsOrderByKey(insId);
        return insOrderEncryptService.decryptInsOrder(insOrder);
    }

    @Override
    public void updateInsOrderByKey(InsOrder insOrder) {
        InsOrder insOrderCopy = insOrderEncryptService.encryptInsOrder(insOrder);
        insOrderDao.updateInsOrderByKey(insOrderCopy);
    }

    @Override
    public int insertInsOrder(InsOrder insOrder) {
        InsOrder insOrderCopy = insOrderEncryptService.encryptInsOrder(insOrder);
        int count = insOrderDao.insertInsOrder(insOrderCopy);
        insOrder.setInsId(insOrderCopy.getInsId());
        return count;
    }
}
